using System.Collections;
using UnityEngine;

public class HiddenLevelController : MonoBehaviour
{
	public static HiddenLevelController instance;

	public int hiddenLevel;

	private float genPosX;

	private Coroutine co;

	private void SpawnEnemy(int num, float genPosX)
	{
		if (TouchEvent.instance.CO_PlayerAI != null)
		{
			num = 0;
		}
		Vector2 pos = new Vector2(genPosX, Random.Range(1f, 5f));
		switch (num)
		{
		case 0:
			Generator.instance.SpawnObj(0, pos);
			break;
		case 1:
			Generator.instance.SpawnObj(17, pos, new float[1]);
			break;
		case 2:
			Generator.instance.SpawnObj(17, pos, new float[1] { 1f });
			break;
		case 5:
			Generator.instance.SpawnObj(18, pos, new float[1] { 1f });
			break;
		case 6:
			Generator.instance.SpawnObj(18, pos, new float[1] { 2f });
			break;
		case 7:
			Generator.instance.SpawnObj(18, pos, new float[1] { 4f });
			break;
		case 8:
			Generator.instance.SpawnObj(18, pos, new float[1] { 3f });
			break;
		case 9:
			Generator.instance.SpawnObj(21, pos);
			break;
		case 10:
			Generator.instance.SpawnObj(22, pos);
			break;
		case 100:
			Generator.instance.SpawnObj(27, pos, new float[1]);
			break;
		}
	}

	private void Awake()
	{
		instance = this;
	}

	public void Init()
	{
		hiddenLevel = PlayerPrefs.GetInt("currentUnlockedCloakNumber");
		SetEnemySpeedByLevel();
		LevelController.instance.StopAllCoroutines();
		if (co != null)
		{
			StopCoroutine(co);
		}
		co = StartCoroutine(IE_SpawnEnemies());
	}

	private IEnumerator IE_SpawnEnemies()
	{
		yield return new WaitForSeconds(1f);
		genPosX = 35f;
		genPosX += Cam.instance.tf.position.x;
		SpawnEnemy(100, genPosX);
		yield return new WaitForSeconds(1f);
		while (!Calc.IsEmptyField() && Player.instance.hp > 0f)
		{
			yield return new WaitForFixedUpdate();
		}
		if (!(Player.instance.hp <= 0f))
		{
			TouchEvent.instance.StopAllCoroutines();
			Player.instance.getDamage = false;
			GM.instance.GO_BTN_Pause.SetActive(false);
			Audio.instance.music[0].Stop();
			GM.instance.SlowMotion(0.02f, 3f);
			yield return new WaitForSecondsRealtime(3.1f);
			Cam.instance.Shake(0.2f, 0.4f);
			GM.instance.IMG_EmenyHP.fillAmount = 0f;
			GM.instance.UnlockTheCloak();
			yield return new WaitForSecondsRealtime(0.1f);
			while (GM.instance.GO_ShowingTheNewEquip.activeSelf)
			{
				yield return null;
			}
			GM.instance.GO_TapToStart.SetActive(false);
			CanvasList.instance.GO_PropsForTitle_Toggle(true);
			GM.instance.Init();
		}
	}

	public void SetEnemySpeedByLevel()
	{
		if (hiddenLevel > 0)
		{
			GM.instance.enemySpeedTimeByLevel = (float)hiddenLevel * 0.01f - 0.1f;
		}
		else
		{
			GM.instance.enemySpeedTimeByLevel = -0.2f;
		}
	}
}
